package online.exceptionHandler;

import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Auther: 狼芒
 * @Date: 2021/9/4 0:09
 * @Descrintion:
 * @version: 1.0
 */
@Order(value = Ordered.HIGHEST_PRECEDENCE)//优先级，数字越小优先级越高
@Slf4j
@Component
public class HandlerException implements HandlerExceptionResolver {
    @SneakyThrows
    @Override
    public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
        log.error("resolveException Custom exception: " + ex);
        ex.printStackTrace();
        response.sendError(555, "自定义异常");
        return new ModelAndView();
    }
}
